package com.fqr;

import java.io.File;

import org.apache.log4j.Logger;

public class FileDestination extends Destination {

	final static Logger logger = Logger.getLogger(FileDestination.class);

	private String filename;
	private String directory;

	public String getDirectory() {
		return directory;
	}

	public void setDirectory(String directory) {
		this.directory = directory;
	}

	public void send(String src) {
		File srcfile = new File(src);
		if (!srcfile.exists()) {
			logger.error("Cannot find " + srcfile.getAbsolutePath());
			return;
		}

		String destFilename;
		if(filename == null || filename.trim().length() == 0)
			destFilename = srcfile.getName();
		else
			destFilename = filename;
		
		if(directory == null)
			directory = System.getProperty("user.dir");
		
		File destFile = new File(directory, destFilename);
		if (destFile.exists())
			destFile.delete();

		srcfile.renameTo(destFile);
		logger.info(srcfile + " is renamed to " + destFile);
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String name) {
		this.filename = name;
	}

}
